package io.renren.modules.tenant.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.tenant.entity.TenantEntity;
import io.renren.modules.tenant.service.TenantService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 机构列表
 *
 * @author zzhaoh
 * @email zhaohzeng@foxmail.com
 * @date 2018-10-31 18:50:29
 */
@RestController
@RequestMapping("tenant/tenant")
public class TenantController {
    @Autowired
    private TenantService tenantService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tenant:tenant:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tenantService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tenantId}")
    @RequiresPermissions("tenant:tenant:info")
    public R info(@PathVariable("tenantId") Long tenantId){
        TenantEntity tenant = tenantService.selectById(tenantId);

        return R.ok().put("tenant", tenant);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tenant:tenant:save")
    public R save(@RequestBody TenantEntity tenant){
		tenantService.insert(tenant);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tenant:tenant:update")
    public R update(@RequestBody TenantEntity tenant){
		tenantService.updateById(tenant);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tenant:tenant:delete")
    public R delete(@RequestBody Long[] tenantIds){
		tenantService.deleteBatchIds(Arrays.asList(tenantIds));

        return R.ok();
    }

}
